package cn.walls1717.ggkt.vod.controller;

import cn.walls1717.ggkt.model.vod.Course;
import cn.walls1717.ggkt.result.Result;
import cn.walls1717.ggkt.vo.vod.CourseFormVo;
import cn.walls1717.ggkt.vo.vod.CoursePublishVo;
import cn.walls1717.ggkt.vo.vod.CourseQueryVo;
import cn.walls1717.ggkt.vod.service.CourseService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程章节相关接口
 *
 * @author walls1717
 * @since 2022/07/14
 */
@Api(tags = "课程章节相关接口")
@RestController
@RequestMapping("/admin/vod/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @ApiOperation("点播课程列表")
    @GetMapping("{pageNum}/{pageSize}")
    public Result<Page<Course>> listPages(@PathVariable Integer pageNum, @PathVariable Integer pageSize,
        CourseQueryVo courseQueryVo) {
        Page<Course> pageInfo = courseService.listPages(pageNum, pageSize, courseQueryVo);
        return Result.success(pageInfo);
    }

    @ApiOperation("添加课程信息")
    @PostMapping("save")
    public Result<?> saveCourse(@RequestBody CourseFormVo courseFormVo) {
        Long id = courseService.saveOrUpdateCourseInfo(courseFormVo);
        return Result.success(id);
    }

    @ApiOperation("根据id获取课程信息")
    @GetMapping("get/{id}")
    public Result<CourseFormVo> getCourseById(@PathVariable Long id) {
        CourseFormVo courseFormVo = courseService.getCourseById(id);
        return Result.success(courseFormVo);
    }

    @ApiOperation("修改课程信息")
    @PostMapping("update")
    public Result<?> updateCourse(@RequestBody CourseFormVo courseFormVo) {
        Long id = courseService.saveOrUpdateCourseInfo(courseFormVo);
        return Result.success(id);
    }

    @ApiOperation("根据id获取课程发布信息")
    @GetMapping("getCoursePublishVo/{id}")
    public Result<CoursePublishVo> getCoursePublishVoById(@PathVariable Long id) {
        CoursePublishVo coursePublishVo = courseService.getCoursePublishVoById(id);
        return Result.success(coursePublishVo);
    }

    @ApiOperation("根据id发布课程")
    @PutMapping("publishCourseById/{id}")
    public Result<?> updatePublishStatusById(@PathVariable Long id) {
        courseService.updatePublishStatusById(id);
        return Result.success();
    }

    @ApiOperation("删除课程")
    @DeleteMapping("remove/{id}")
    public Result<?> deleteCourse(@PathVariable Long id) {
        courseService.removeCourse(id);
        return Result.success();
    }

    @ApiOperation("查询所有课程")
    @GetMapping("findAll")
    public Result<List<Course>> listCourses() {
        List<Course> list = courseService.listCourses();
        return Result.success(list);
    }
}
